<!-- 退卡记录页面 -->
<template>
  <div>
    <div class="cardRefundRecord-wrap">
      <div class="title-box">退卡记录</div>
      <div class="search-content">
        <div class="datetimerange-type-box">
          <el-date-picker
            @change="onSearch"
            v-model="pageParam.betweenTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
          <div class="refund-type">
            <div class="desc">充值方式</div>
            <el-select
              v-model="pageParam.refund_type"
              clearable
              @change="onSearch"
              style="width: 220px"
              placeholder="请选择"
            >
              <el-option
                v-for="item in rechangeTypeOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </div>
        </div>
        <!-- <div class="search-input-box">
            <img class="search-icon" src="@/assets/images/home/search-icon.png" alt="" />
            <input
              class="input"
              v-model="pageParam.search"
              type="text"
              placeholder="搜索会员卡号/会员姓名/操作人"
              @keyup.enter="onSearch"
              @input="onSearch"
            />
          </div> -->
        <div class="search-input-button">
          <div class="search-input-box">
            <img class="search-icon" src="@/assets/images/home/search-icon.png" alt="" />
            <input
              class="input"
              v-model="pageParam.search"
              type="text"
              placeholder="搜索会员卡号/会员姓名/操作人"
              @keyup.enter="onSearch"
              @input="onSearch"
            />
          </div>
        </div>
      </div>
      <div class="table-box">
        <el-table
          :data="tableData"
          style="width: 100%"
          border
          v-loading="tableLoading"
          element-loading-text="加载中..."
        >
          <el-table-column align="center" prop="log_id" label="ID"> </el-table-column>
          <el-table-column align="center" prop="user_id" label="会员卡号"> </el-table-column>
          <el-table-column align="center" prop="user.real_name" label="会员姓名"> </el-table-column>
          <el-table-column align="center" prop="balance" label="会员余额"> </el-table-column>
          <el-table-column align="center" prop="money" label="退还金额"> </el-table-column>
          <el-table-column align="center" prop="id" label="退还方式">
            <template #default="{ row }">
              {{ refundTypeEnum[row.refund_type] }}
            </template>
          </el-table-column>
          <el-table-column align="center" prop="storeUser.real_name" label="操作人">
          </el-table-column>
          <el-table-column align="center" prop="create_time" label="退卡时间"> </el-table-column>
        </el-table>
      </div>
      <div class="dialog-pagination">
        <!-- 分页器 -->
        <Pagination
          v-show="total > 0"
          :total="total"
          v-model:page="pageParam.page"
          v-model:limit="pageParam.limit"
          @pagination="handlePagination"
          :pageSizes="[15, 45, 75, 100]"
        />
      </div>
      <div class="table-bottom-box">
        <div class="desc"></div>
        <div class="back-btn" @click="handleBack">返回</div>
      </div>
    </div>
  </div>
</template>
<script setup>
import Pagination from '@/components/Pagination/Index.vue'
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
// 引入会员接口api
import * as memberApi from '@/api/member'
import { debounce } from '@/utils/toolsValidate'

// 路由实例
const router = useRouter()

// 响应式数据
const datetimerangeList = ref([])
const tableData = ref([])
const total = ref(0)
const rechangeTypeOptions = ref([
  { value: 10, label: '现金' },
  { value: 20, label: '微信' },
  { value: 30, label: '支付宝' }
])
const pageParam = ref({
  search: '',
  refund_type: '',
  betweenTime: [],
  page: 1,
  limit: 15
})
const refundTypeEnum = ref({
  10: '现金',
  20: '微信',
  30: '支付宝'
})
const rechangeType = ref('')
const searchKeyword = ref('')
const tableLoading = ref(false)

// 生命周期钩子
onMounted(() => {
  getRefundRecordList()
})

// 返回上一页
const handleBack = () => {
  router.back()
}

// 点击搜索按钮
const onSearch = debounce(() => {
  pageParam.value.page = 1
  getRefundRecordList()
}, 300)

// 分页事件处理
const handlePagination = paginationData => {
  pageParam.value.page = paginationData.page
  pageParam.value.limit = paginationData.limit
  getRefundRecordList()
}

// 获取退卡记录列表
const getRefundRecordList = () => {
  tableLoading.value = true
  memberApi
    .fetchRefundCardList(pageParam.value)
    .then(res => {
      if (res.status === 200) {
        total.value = res?.data?.list?.total || 0
        tableData.value = res?.data?.list?.data?.length > 0 ? res.data.list.data : []
      }
    })
    .finally(() => {
      tableLoading.value = false
    })
}
</script>
<style lang="scss" scoped>
::v-deep {
  .el-table {
    border-radius: 12px;
    height: 600px;
  }
  .el-table__body-wrapper {
    height: 600px;
    overflow-y: auto;
  }
  //滚动条整体的大小
  .el-table__body-wrapper::-webkit-scrollbar {
    width: 6px !important;
    height: 0 !important;
  }
  //滚动条里滑动的滑块
  .el-table__body-wrapper::-webkit-scrollbar-thumb {
    height: 200px !important;
    background: #d2d2d2 !important;
    border-radius: 3px !important;
  }
  //滚动条底层样式
  .el-table__body-wrapper::-webkit-scrollbar-track {
    display: none !important;
  }
  .el-table th.el-table__cell {
    background: #a85b62;
    color: #fff !important;
  }
  .el-input__inner {
    border-radius: 12px;
  }
  .el-button {
    color: #fff;
    background-color: #7b0a03;
    border-color: #7b0a03;
    height: 46px;
    border-radius: 12px;
    margin-left: 20px;
  }
}
.cardRefundRecord-wrap {
  box-sizing: border-box;
  width: 1600px;
  height: 1050px;
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 3px 0px 24px 0px rgba(0, 0, 0, 0.16);
  .title-box {
    height: 88px;
    line-height: 88px;
    background: #f4f4f4;
    border-radius: 20px 20px 0px 0px;
    font-size: 20px;
    font-family:
      PingFang SC,
      PingFang SC-Bold;
    font-weight: 700;
    text-align: center;
    color: #333333;
  }
  .search-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 30px;
    box-shadow: 0px 3px 6px 0px rgba(0, 0, 0, 0.04);
    .datetimerange-type-box {
      display: flex;
      align-items: center;
      .refund-type {
        display: flex;
        align-items: center;
        margin-left: 20px;
        .desc {
          font-size: 16px;
          font-family:
            PingFang SC,
            PingFang SC-Regular;
          font-weight: 400;
          text-align: left;
          color: #333333;
          margin-right: 20px;
        }
      }
    }
    .search-input-button {
      display: flex;
      align-items: center;
      .search-input-box {
        width: 300px;
        height: 46px;
        border: 1px solid #d2d2d2;
        border-radius: 25px;
        box-sizing: border-box;
        display: flex;
        align-items: center;
        padding-left: 20px;
        .search-icon {
          flex-shrink: 0;
          width: 24px;
          height: 24px;
        }
        .input {
          border: none;
          outline: none;
          width: 230px;
          font-size: 16px;
          font-family:
            PingFang SC,
            PingFang SC-Regular;
          font-weight: 400;
          text-align: left;
          color: #333;
          margin-left: 10px;
        }
        .search-btn {
          height: 46px;
          // right: 0;
          left: 55px;
          background: #7b0a03;
          border: none;
          border-radius: 10px;
          margin-left: 70px;
        }
      }
    }
  }
  .table-box {
    // width: 1499px;
    padding: 0px 50px;
    padding-top: 20px;
    box-sizing: border-box;
  }
  .dialog-pagination {
    display: flex;
    justify-content: center;
    margin-top: 10px;
  }
  .table-bottom-box {
    padding: 0 50px 0 50px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .desc {
      font-size: 14px;
      font-family:
        PingFang SC,
        PingFang SC-Regular;
      font-weight: 400;
      text-align: left;
      color: #333333;
    }
    .back-btn {
      width: 121px;
      height: 52px;
      line-height: 52px;
      background: #ffffff;
      border: 1px solid #333333;
      border-radius: 12px;
      font-size: 18px;
      font-family:
        PingFang SC,
        PingFang SC-Regular;
      font-weight: 400;
      text-align: center;
      color: #333333;
      cursor: pointer;
    }
    .back-btn:hover {
      color: #7c0a03;
      border-color: #7c0a03;
    }
  }
}
</style>
